package com.yh.homestay.controller;

import com.yh.homestay.common.GuestsCarEditResult;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.GuestsCar;
import com.yh.homestay.service.GuestsCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 车辆管理
 */
@Controller
/**
 * 查看车辆信息列表
 */
public class GuestsCarController {
    @Autowired
    private GuestsCarService guestsCarService;

    @RequestMapping(value="/carList", produces = "application/json; charset=utf-8")
    @ResponseBody
    public HomeStayResult selectAll(Integer page, Integer limit, String carType) {
        HomeStayResult resultMessage = guestsCarService.selectAll(page, limit,carType);
        return resultMessage;
    }

    /**
     * 添加车辆信息
     */
    @RequestMapping("/addCar")
    @ResponseBody
    public HomeStayResult addCar(GuestsCar guestsCar) {
        HomeStayResult homStayResult = guestsCarService.addCar(guestsCar);
        return homStayResult;
    }

    /**
     * 修改车辆信息
     */
//    @RequestMapping("/car/toEditCar/{id}")
//    @ResponseBody
//    public CarEditResult toEditguests(@PathVariable String id) {
//        CarEditResult res = guestsCarService.selecteCarById(id);
//        return res;
//    }

    @RequestMapping("/car-edit/{id}")
    @ResponseBody
    public HomeStayResult editguests(String id, String carType, String carColor, Integer carHoldCount, Integer carStatus) {
        HomeStayResult update = guestsCarService.update(id, carType, carColor, carHoldCount, carStatus);
        return update;
    }

    /**
     * 删除车辆信息
     */
    @RequestMapping("/car-delete/{id}")
    @ResponseBody
    public HomeStayResult deleteById(@PathVariable String id) {
        HomeStayResult delete = guestsCarService.delete(id);
        return delete;
    }
    /**
     * 批量删除
     */
    @ResponseBody
    @RequestMapping("/deleteCarS")
    public HomeStayResult delete(@RequestParam List<String> ids){
        HomeStayResult delete = guestsCarService.deleteCarS(ids);
        return  delete;
    }
    /**
     * 跳转编辑页面渲染数据
     */
    @RequestMapping("/car-edit/selectOne/{id}")
    @ResponseBody
    public GuestsCarEditResult editcar(@PathVariable String id){
        return  guestsCarService.selectone(id);
    }
    /**
     * 编辑页面传回id和数据展示
     */
    @RequestMapping("/car-update")
    @ResponseBody
    public GuestsCarEditResult updateCar(GuestsCar guestsCar){
        return  guestsCarService.updateGuestsCar(guestsCar);
    }

}